Python/Python Mcq Set 13 Sample Test,Sample questions

Question:
 What will be the output of the following Python code?

def a(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return a(n-1)+a(n-2)
for i in range(0,4):
    print(a(i),end=" ")

1.0 1 2 3

2.An exception is thrown

3.0 1 1 2 3

4. 0 1 1 2

Posted Date:-2022-01-02 03:14:18


Question:
 What will be the output of the following Python code?

f=lambda x:bool(x%2)
print(f(20), f(21))

1.False True

2. False False

3. True True

4.True False

Posted Date:-2022-01-02 03:23:58


Question:
 What will be the output of the following Python code?

l=[-2, 4]
m=map(lambda x:x*2, l)
print(m)

1. [-4, 16]

2.Address of m

3.Error

4.-4 16

Posted Date:-2022-01-02 03:25:16


Question:
 What will be the output of the following Python code?

l=[1, -2, -3, 4, 5]
def f1(x):
    return x<2
m1=filter(f1, l)
print(list(m1))

1. [1, 4, 5 ]

2.Error

3. [-2, -3]

4.[1, -2, -3]

Posted Date:-2022-01-02 03:24:48


Question:
 What will be the output of the following Python code?

l=[1, 2, 3, 4, 5]
m=map(lambda x:2**x, l)
print(list(m))

1.[1, 4, 9, 16, 25 ]

2. [2, 4, 8, 16, 32 ]

3.[1, 0, 1, 0, 1]

4.error

Posted Date:-2022-01-02 03:26:41


Question:
 Which of these is not true about recursion?

1. Making the code look clean

2.A complex task can be broken into sub-problems

3.Recursive calls take up less memory

4.Sequence generation is easier than a nested iteration

Posted Date:-2022-01-02 03:13:00


Question:
 Which type of copy is shown in the following python code?

l1=[[10, 20], [30, 40], [50, 60]]
ls=list(l1)
ls
[[10, 20], [30, 40], [50, 60]]

1.Shallow copy

2.Deep copy

3.memberwise

4.all of the mentioned

Posted Date:-2022-01-02 03:15:06


Question:
Fill in the line of the following Python code for calculating the factorial of a number.

def fact(num):
    if num == 0: 
        return 1
    else:
        return _________

1. num*fact(num-1)

2. (num-1)*(num-2)

3.num*(num-1)

4.fact(num)*fact(num-1)

Posted Date:-2022-01-02 03:09:19


Question:
In _______ copy, the base address of the objects are copied. In ________ copy, the base address of the objects are not copied.

1.deep. shallow

2.memberwise, shallow

3. shallow, deep

4.deep, memberwise

Posted Date:-2022-01-02 03:15:45


Question:
In _________copy, the modification done on one list affects the other list. In ________ copy, the modification done on one list does not affect the other list.

1. shallow, deep

2. memberwise, shallow

3.deep, shallow

4. deep, memberwise

Posted Date:-2022-01-02 03:18:37


Question:
Observe the following Python code?

def a(n):
    if n == 0:
        return 0
    else:
        return n*a(n - 1)
def b(n, tot):
    if n == 0:
        return tot
    else:
        return b(n-2, tot-2)

1.Both a() and b() aren’t tail recursive

2.Both a() and b() are tail recursive

3.b() is tail recursive but a() isn’t

4.b() is tail recursive but a() isn’t

Posted Date:-2022-01-02 03:11:09


Question:
Read the following Python code carefully and point out the global variables?

y, z = 1, 2
def f():
    global x
    x = y+z

1. x

2. y and z

3. x, y and z

4.Neither x, nor y, nor z

Posted Date:-2022-01-02 03:02:57


Question:
What happens if a local variable exists with the same name as the global variable you want to access?

1. Error

2. The local variable is shadowed

3.Undefined behavior

4.The global variable is shadowed

Posted Date:-2022-01-02 03:06:32


Question:
What happens if the base condition isn’t defined in recursive programs?

1. Program gets into an infinite loop

2.Program runs once

3.Program runs n number of times where n is the argument given to the function

4.An exception is thrown

Posted Date:-2022-01-02 03:12:32


Question:
What is tail recursion?

1.A recursive function that has two base cases

2.A function where the recursive functions leads to an infinite loop

3. A recursive function where the function doesn’t return anything and just prints the values

4. A function where the recursive call is the last thing executed by the function

Posted Date:-2022-01-02 03:10:42


Question:
What is the base case in the Merge Sort algorithm when it is solved recursively?

1.n=0

2.n=1

3.A list of length one

4.An empty list

Posted Date:-2022-01-02 03:20:05


Question:
What will be the output of the following Python code and state the type of copy that is depicted?

l1=[2, 4, 6, 8]
l2=[1, 2, 3]
l1=l2
l2

1. [2, 4, 6, 8], shallow copy

2.[2, 4, 6, 8], deep copy

3. [1, 2, 3], shallow copy

4.[1, 2, 3], deep copy

Posted Date:-2022-01-02 03:16:16


Question:
What will be the output of the following Python code?

a = [1, 2, 3, 4, 5]
b = lambda x: (b (x[1:]) + x[:1] if x else []) 
print(b (a))

1. 1 2 3 4 5

2.[5,4,3,2,1]

3. []

4.Error, lambda functions can’t be called recursively

Posted Date:-2022-01-02 03:20:35


Question:
What will be the output of the following Python code?

a=10
globals()['a']=25
print(a)

1.10

2.25

3. Junk value

4.error

Posted Date:-2022-01-02 03:07:05


Question:
What will be the output of the following Python code?

def check(n):
    if n < 2:
        return n % 2 == 0
    return check(n - 2)
print(check(11))

1. False

2. True

3.1

4.An exception is thrown

Posted Date:-2022-01-02 03:19:38


Question:
What will be the output of the following Python code?

def f():
    global a
    print(a)
    a = "hello"
    print(a) 
a = "world" 
f()
print(a)

1. hello hello world

2. world hello hello

3. hello world world

4. world hello world

Posted Date:-2022-01-02 02:58:07


Question:
What will be the output of the following Python code?

def f(): x=4
x=1
f()
x

1.Error

2.4

3.Junk value

4. 1

Posted Date:-2022-01-02 03:07:36


Question:
What will be the output of the following Python code?

def f(p, q, r):
    global s
    p = 10
    q = 20
    r = 30
    s = 40
    print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)

1.1 2 3 4

2.5 10 15 4

3.10 20 30 40

4. 5 10 15 40

Posted Date:-2022-01-02 02:59:07


Question:
What will be the output of the following Python code?

def f(x):
    print("outer")
    def f1(a):
        print("inner")
        print(a,x)
f(3)
f1(1)

1.outer error

2.inner error

3.outer inner

4. error

Posted Date:-2022-01-02 02:59:41


Question:
What will be the output of the following Python code?

def f1():
    global x
    x+=1
    print(x)
x=12
print("x")

1. Error

2.13

3.13 x

4. x

Posted Date:-2022-01-02 02:56:26


Question:
What will be the output of the following Python code?

def f1():
    x=100
    print(x)
x=+1
f1()

1. Error

2.100

3.101

4. 99

Posted Date:-2022-01-01 19:06:19


Question:
What will be the output of the following Python code?

def f1():
    x=15
    print(x)
x=12
f1()

1. Error

2.12

3. 15

4.1512

Posted Date:-2022-01-01 19:01:58


Question:
What will be the output of the following Python code?

def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))

1.[3,2,4]

2. [2,3,4]

3.Error

4.[3,4,2]

Posted Date:-2022-01-02 02:58:40


Question:
What will be the output of the following Python code?

def f1(x):
    global x
    x+=1
    print(x)
f1(15)
print("hello")

1.error

2.hello

3.16

4.16 hello

Posted Date:-2022-01-02 02:56:58


Question:
What will be the output of the following Python code?

def fun(n):
    if (n > 100):
        return n - 5
    return fun(fun(n+11));
 
print(fun(45))

1. 50

2. 100

3. 74

4.Infinite loop

Posted Date:-2022-01-02 03:12:06


Question:
What will be the output of the following Python code?

def san(x):
    print(x+1)
x=-2
x=4
san(12)

1. 13

2. 10

3.2

4.5

Posted Date:-2022-01-01 19:11:37


Question:
What will be the output of the following Python code?

def test(i,j):
    if(i==0):
        return j
    else:
        return test(i-1,i+j)
print(test(4,7))

1.13

2. 7

3.Infinite loop

4.17

Posted Date:-2022-01-02 03:09:46


Question:
What will be the output of the following Python code?

e="butter"
def f(a): print(a)+e
f("bitter")

1.error

2. butter error

3. bitter error

4.bitterbutter

Posted Date:-2022-01-02 03:05:57


Question:
What will be the output of the following Python code?

import functools
l=[1,2,3,4]
print(functools.reduce(lambda x,y:x*y,l))

1. Error

2.10

3.24

4.No output

Posted Date:-2022-01-02 03:24:24


Question:
What will be the output of the following Python code?

l1=[1, 2, 3, (4)]
l2=l1.copy()
l2
l1

1.[1, 2, 3, (4)] [1, 2, 3, 4]

2.[1, 2, 3, 4] [1, 2, 3, (4)]

3.[1, 2, 3, 4] [1, 2, 3, 4]

4.[1, 2, 3, (4)] [1, 2, 3, (4)]

Posted Date:-2022-01-02 03:19:09


Question:
What will be the output of the following Python code?

l1=[1, 2, 3, [4]]
l2=list(l1)
id(l1)==id(l2)

1. True

2.False

3. Error

4.Address of l1

Posted Date:-2022-01-02 03:17:29


Question:
What will be the output of the following Python code?

l1=[10, 20, 30, [40]]
l2=copy.deepcopy(l1)
l1[3][0]=90
l1
l2

1.[10, 20, 30, [40]] [10, 20, 30, 90]

2.Error

3.[10, 20, 30 [90]] [10, 20, 30, [40]]

4.[10, 20, 30, [40]] [10, 20, 30, [90]]

Posted Date:-2022-01-02 03:18:03


Question:
What will be the output of the following Python code?

l1=[10, 20, 30]
l2=l1
id(l1)==id(l2)
 
l2=l1.copy()
id(l1)==id(l2)

1.False, False

2. False, True

3.True, True

4.True, False

Posted Date:-2022-01-02 03:16:43


Question:
What will be the output of the following Python code?

l=[1, -2, -3, 4, 5]
def f1(x):
    return x<-1
m1=map(f1, l)
print(list(m1))

1.[False, False, False, False, False]

2.[False, True, True, False, False]

3. [True, False, False, True, True]

4. [True, True, True, True, True]

Posted Date:-2022-01-02 03:25:46


Question:
What will be the output of the following Python code?

l=[]
def convert(b):
    if(b==0):
        return l
    dig=b%2
    l.append(dig)
    convert(b//2)
convert(6)
l.reverse()
for i in l:
    print(i,end="")

1.011

2.110

3.3

4.Infinite loop

Posted Date:-2022-01-02 03:10:12


Question:
What will be the output of the following Python code?

odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
    if odd(i):
        continue
    else:
        break

1. [0, 2, 4, 6, 8, 10]

2. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

3.[1, 3, 5, 7, 9]

4. error

Posted Date:-2022-01-02 03:23:11


Question:
What will be the output of the following Python code?

x = 5 
def f1():
    global x
    x = 4
def f2(a,b):
    global x
    return a+b+x
f1()
total = f2(1,2)
print(total)

1. Error

2.7

3.8

4.15

Posted Date:-2022-01-02 03:00:14


Question:
What will be the output of the following Python code?

x=1
def cg():
	global x
	x=x+1	
cg()
x

1.2

2.1

3. 0

4. error

Posted Date:-2022-01-02 03:05:25


Question:
What will be the output of the following Python code?

x=100
def f1():
    global x
    x=90
def f2():
    global x
    x=80
print(x)

1.100

2. 90

3. 80

4. error

Posted Date:-2022-01-02 03:00:44


Question:
What will be the output of the following Python code?

x=12
def f1(a,b=x):
    print(a,b)
x=15
f1(4)

1. Error

2.12 4

3.4 12

4.4 15

Posted Date:-2022-01-02 02:57:28


Question:
Which is the most appropriate definition for recursion?

1. A function that calls itself

2.A function execution instance that calls another execution instance of the same function

3. A class method that calls another class method

4.An in-built method that is automatically called

Posted Date:-2022-01-02 03:08:22


Question:
Which of the following data structures is returned by the functions globals() and locals()?

1. list

2. set

3.dictionary

4.tuple

Posted Date:-2022-01-02 03:04:59


Question:
Which of the following statements is false about recursion?

1.Every recursive function must have a base case

2.Infinite recursion can occur if the base case isn’t properly mentioned

3.A recursive function makes the code easier to understand

4.Every recursive function must have a return value

Posted Date:-2022-01-02 03:11:39


Question:
Which of these is false about recursion?

1.Recursive function can be replaced by a non-recursive function

2.Recursive functions usually take more memory space than non-recursive function

3.Recursive functions run faster than non-recursive function

4.Recursion makes programs easier to understand

Posted Date:-2022-01-02 03:08:47


Question:
Which of these is not true about recursion?

1. It’s easier to code some real-world problems using recursion than non-recursive equivalent

2. Recursive functions are easy to debug

3.Recursive calls take up a lot of memory

4.Programs using recursion take longer time than their non-recursive equivalent

Posted Date:-2022-01-02 03:13:51


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!